import request from '@/utils/request'
import type { PageResult, Result } from '@/types'

export interface StudentScore {
  id?: number
  studentId: number
  studentName?: string  // 学生姓名
  studentNo?: string    // 学号
  courseName: string
  score: number
  credit: number
  semester: string
  createUser?: number
  createTime?: string
  updateTime?: string
}

/**
 * 分页查询成绩
 */
export function getScorePage(params: any) {
  return request<PageResult<StudentScore>>({
    url: '/score/page',
    method: 'get',
    params
  })
}

/**
 * 获取学生所有成绩
 */
export function getScoreByStudentId(studentId: number) {
  return request<Result<StudentScore[]>>({
    url: `/score/student/${studentId}`,
    method: 'get'
  })
}

/**
 * 新增成绩
 */
export function addScore(data: StudentScore) {
  return request<Result<void>>({
    url: '/score',
    method: 'post',
    data
  })
}

/**
 * 更新成绩
 */
export function updateScore(data: StudentScore) {
  return request<Result<void>>({
    url: '/score',
    method: 'put',
    data
  })
}

/**
 * 删除成绩
 */
export function deleteScore(id: number) {
  return request<Result<void>>({
    url: `/score/${id}`,
    method: 'delete'
  })
}

/**
 * 学生查询自己的成绩
 */
export function getMyScores(params: {
  current: number
  size: number
  semester?: string
  courseName?: string
}) {
  return request<Result<PageResult<StudentScore>>>({
    url: '/score/my-scores',
    method: 'get',
    params
  })
}

